﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;


namespace ODS
{
    [DataContract]
    public class GooglePlaceRespond
    {
        public GooglePlaceRequest Request { get; set; }

        [DataMember(Name = "results")]
        public List<GooglePlace> Places { get; private set; }

        [DataMember(Name = "status")]
        public String Status { get; set; }

        [DataMember(Name = "next_page_token")]
        public string NextPageToken { get; set; }

        public GooglePlaceRespond()
        {
            Places = new List<GooglePlace>();
            NextPageToken = "";
        }

        public GooglePlaceRespond(GooglePlaceRequest Request)
            : this()
        {
            this.Request = Request;
        }


        public static GooglePlaceRespond ParseFromJSON(String jsonData)
        {

            GooglePlaceRespond  output;
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(GooglePlaceRespond));
            using (MemoryStream stream =  new MemoryStream(Encoding.Unicode.GetBytes(jsonData)))
            {
                output =  serializer.ReadObject(stream) as GooglePlaceRespond;
            }
            return output;
        }
    }

    [DataContract()]
    public class GooglePlace
    {

        public GooglePlace()
        {
            Rating = -1;
            Types = new List<string>();
        }


        [DataMember(Name = "id")]
        public string Id { get; set; }

        [DataMember(Name = "icon")]
        public string IconUrl { get; set; }

        [DataMember(Name = "reference")]
        public string ReferenceId { get; set; }

        [DataMember(Name = "types")]
        public List<string> Types { get; set; }

        [DataMember(Name = "name")]
        public string Name { get; set; }

        [DataMember(Name = "vicinity")]
        public string Address { get; set; }

        [DataMember(Name = "rating")]
        public double Rating { get; set; }

        [DataMember(Name = "geometry")]
        public geometry Geometry { get; set; }

        [DataContract(Name = "geometry")]
        public class geometry
        {
            [DataMember(Name = "location")]
            public location Location { get; set; }

            [DataContract(Name = "location")]
            public class location
            {
                [DataMember(Name = "lat")]
                public double Lattitude { get; set; }

                [DataMember(Name = "lng")]
                public double Longitude { get; set; }
            }
        }
    }

    
}
